package com.fresh.fresh.controller;

import com.fresh.fresh.dao.Cart;
import com.fresh.fresh.dao.Orders;
import com.fresh.fresh.service.OderService;
import com.fresh.fresh.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 订单
 */
@RestController
@RequestMapping("/order")
@Api(tags = "订单接口")
public class OrderController {

    @Autowired
    OderService oderService;

    @PostMapping("/addOrder")
    @ApiOperation("新增订单接口")
    public Result<?> addGoods(@RequestBody List<Cart> items) {
        oderService.addGoods(items);
        return Result.success();
    }

    //删除订单
    @DeleteMapping("/id={id}")
    @ApiOperation("删除订单接口")
    public Result<?> getGoods(@PathVariable Integer id) {
        oderService.deleteOder(id);
        return Result.success();
    }

    //获取对应用户的订单
    @GetMapping("/allOrder/{userId}")
    @ApiOperation("对应用户的订单接口")
    public Result<?> getFindOrder(@PathVariable Integer userId) {
        List<Orders> data = oderService.getFindAll(userId);
        return Result.success(data);
    }

    @PostMapping("/update")
    @ApiOperation("新增订单接口")
    public Result<?> update(@RequestBody Orders orders) {
        Orders order = new Orders();
        order.setPayTime(orders.getPayTime());
        oderService.updateOrder(orders);
        return Result.success();
    }

}
